package com.huiquan.vocab.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabDyadPosition;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class VocabDyadPositionDao extends EnhancedBaseDao<VocabDyadPosition> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_DYAD_POSITION.";

	public VocabDyadPositionDao() {
		super(space);
	}

	public void init() {
		this.update(space + "INIT", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> retrieveOStdList(Map<String, Object> param) {
		return (List<String>)this.list(space + "RETRIEVE_O_STD_LIST",param, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<VocabDyadPosition> retrieveListByOStd(String oStd) {
		Map<String, Object> param = new HashMap<>();
		param.put("oStd", oStd);
		return (List<VocabDyadPosition>)this.list(space + "RETRIEVE_LIST_BY_O_STD",param, sqlMapClient);
	}
	public void changeElementSynonym(String id, String elementSynonym, User user) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("elementSynonym", elementSynonym);
		param.put("uid", user.getUserId());
		
		this.update(space + "CHANGE_ELEMENT_SYNONYM", param, sqlMapClient);
	}

	public void batchUpdateCheckFlag(String oStd, User user) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("oStd", oStd);
		param.put("uid", user.getUserId());
		
		this.update(space + "BATCH_UPDATE_CHECK_FLAG", param, sqlMapClient);
	}
	public void updateCheckFlag(String id,User user) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("uid", user.getUserId());

		this.update(space + "UPDATE_CHECK_FLAG", param, sqlMapClient);
	}
	public void changeDisplayP(String id, String displayP) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("displayP", displayP);
		
		this.update(space + "CHANGE_DISPLAY_P", param, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> checkStdFlag() {
		return (List<String>)this.list(space + "CHECK_STD_FLAG", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveDisplayP() {
		return (List<Map<String, String>>)this.list(space + "RETRIEVE_DISPLAY_P", sqlMapClient);
	}
	public void changeDisplayFlag(String id, String displayFlag, User user) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("displayFlag", displayFlag);
		param.put("uid", user.getUserId());
		
		this.update(space + "CHANGE_DISPLAY_FLAG", param, sqlMapClient);
	}
	public Long insertVocabulary(VocabDyadPosition entity) {
		return (Long) insert(space + "INSERT_VOCABULARY", entity, sqlMapClient);
	}
	public int checkPositionByArray(Map<String, Object> param) {
		Integer size = (Integer) this.object(space + "CHECK_POSITION_BY_ARRAY", param, sqlMapClient);
		return size == null ? 0 : size;
	}
	public long getPosition(Map<String, Object> param) {
		Long size = (Long) this.object(space + "RETRIEVE_POSITION_BY_O_RIGHT_DYAD_STD",param, sqlMapClient);
		return size == null ? 0 : size;

	}
}
